<?php

//Retrieve last 5 slides
    $args = array(
        'posts_per_page'   => 5,
        'offset'           => 0,
        'category'         => '',
        'category_name'    => '',
        'orderby'          => 'post_date',
        'order'            => 'DESC',
        'include'          => '',
        'exclude'          => '',
        'meta_key'         => '',
        'meta_value'       => '',
        'post_type'        => 'slide',
        'post_mime_type'   => '',
        'post_parent'      => '',
        'post_status'      => 'publish',
        'suppress_filters' => true 

    );
    $slides = get_posts($args);
    $user_ID = get_current_user_id();
?>
<!-- Header Carousel -->
    <header id="myCarousel" class="carousel slide">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <?php
                $length = count($slides);

                for($i=0;$i<$length;$i++){
                    if($i == 0){
                        $class = "active";
                    }else{
                        $class = "";
                    }
                    echo '<li data-target="#myCarousel" data-slide-to="' . $i . '" class=" ' . $class .'"></li>';
                }
            ?>
        </ol>

        <!-- Wrapper for slides -->
        <div class="carousel-inner">
            <?php 
            $length = count($slides);
            for($i=0;$i<$length;$i++){
                    if($i == 0){
                        $class = "active";
                    }else{
                        $class = "";
                    }
                    $thumbnail_id = get_post_thumbnail_id($post->ID);
                    $thumbnail_object = get_post($thumbail_id);
                    $popup_event = get_post_meta ( $slides[$i]->ID, '_popup_event', true);
                    $popup_link = get_post_meta ($slides[$i]->ID, '_slide_link', true );
                    $popup_text = get_post_meta( $slides[$i]->ID, '_slide_text', true );
                    ?>
                    <div class="item <?php echo $class;?>">
                        <div class="fill" style="background-image:url('<?php echo get_the_post_thumbnail_src(get_the_post_thumbnail( $slides[$i]->ID, array( 1900, 1080)) );?>');"></div>
                        <div class="carousel-caption">
                            <h1>
                                <a class="slider-link" href="<?php if ($popup_link <> ""){
                                    echo $popup_link;
                                    }else{ echo "#";} ?>">
                                    <?php echo $slides[$i]->post_title; ?>
                                </a>
                            </h1>
                            <h3><?php echo $slides[$i]->post_content; ?></h3>
                            <?php if (empty($user_ID)) {?>
                               <div class='btn-div'>
                                    <div onclick=<?php echo $popup_event; ?>
                                        type='button' class='btn btn-sm btn-success capitalize'>
                                           <?php echo $popup_text; ?> 
                                        </div>
                                    </div>
                                <?php } ?>
                            
                        </div>
                    </div>  
                    <?php } ?>          
                  
        </div>

        <!-- Controls -->
        <a class="left carousel-control" href="#myCarousel" data-slide="prev">
            <span class="icon-prev"></span>
        </a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next">
            <span class="icon-next"></span>
        </a>
    </header>